const koa = require('koa');
const app = new koa();
var cors = require('koa2-cors');
const {mongo} = require('./database/init.js');
app.use(cors({
    origin: function (ctx) {
        //访问主域名下的test地址不允许跨域
        if (ctx.url === '/test') {
            return false;
        }
        return '*';
    },
    exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
    maxAge: 5,
    credentials: true,
    allowMethods: ['GET', 'POST', 'DELETE'],
    allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}));

;(async()=>{
    var data  = await mongo();
    app.use(async ctx=>{
        ctx.body = data;
    })
})()
app.listen(8080)